<?php
/**
 * Dirox Framework
 * Copyright (C) 2005 - 2007 Dirox / Synexser
 * 
 * All rights reserved.
 */

//set include path to library folder and application folder
set_include_path('.' . PATH_SEPARATOR . APPLICATION_DIR_BO .'/library/external/'.
				PATH_SEPARATOR . APPLICATION_DIR_BO .'/library/external/PEAR/'.
                PATH_SEPARATOR . APPLICATION_DIR_BO .'/application/include/'.
				PATH_SEPARATOR . APPLICATION_DIR_BO .'/library/class/'. get_include_path());


//include constant config file (store config for DB, mail auto send...)
//include("app_config.php");
//include("app_constant.php");

include("functions.php");
require("DRX.php");
require("DRX_Common.php");

//============================= Missing app config constants =================//
if (!defined('DEFAULT_CONTROLLER')) { define('DEFAULT_CONTROLLER','index'); }
if (!defined('DEFAULT_CONTROLLER_ACTION')) { define('DEFAULT_CONTROLLER_ACTION','index'); }
if (!defined('APPLICATION_URL')) { define('APPLICATION_URL',''); }
if (!defined('APPLICATION_DIR')) { define('APPLICATION_DIR',''); }
if (!defined('USE_LOWERCASE_FILENAMES')) { define('USE_LOWERCASE_FILENAMES',false); }
//========================= End Missing app config constants =================//

//============================= Timezone config ==============================//
if (!defined('TIMEZONE'))
{
	define('TIMEZONE','Europe/Paris');
}
date_default_timezone_set(TIMEZONE);
//============================ End Timezone config ===========================//

//============================= Initialize framework objects =================//
DRX_RequestHandler::initialize();
//========================= End Initialize framework objects =================//

//============================= DB_DataObject & MDB2 config =============================//
require_once("DRX_DataObject.php");
require_once("DRX_DataObject_Cast.php");

$options = &PEAR::getStaticProperty( 'DB_DataObject', 'options' );
$options = array(
	'schema_location'				=> 'application/model',
	'class_location'				=> 'application/model',
	'require_prefix'				=> 'model',
	'class_prefix'					=> 'DataObjects_',
	'auto_quote'					=> 'on',
	'db_driver'						=> (defined('DATABASE_DRIVER') ? DATABASE_DRIVER : 'MDB2')
);
$options = array_merge($options, $database_dsn);

$mdb2_options = &PEAR::getStaticProperty( 'MDB2', 'options' );
if (!is_array($mdb2_options)) { $mdb2_options = array(); }
$mdb2_options['quote_identifier'] = true;
//=========================== End DB_DataObject & MDB2 config ===========================//

//============================== Smarty config ===============================//
$smarty = new DRX_Smarty();
$smarty->left_delimiter =  '<{';
$smarty->right_delimiter =  '}>';

$smarty->caching      = false;

$smarty->config_overwrite = true;
DRX::register("smarty", $smarty);
//============================ End smarty config =============================//

//============================= i18n setup ===================================//
if (!defined("ACTIVATE_UTF8_SUPPORT"))
{
	define ("ACTIVATE_UTF8_SUPPORT", true);
}

if (ACTIVATE_UTF8_SUPPORT)
{
	// For compatibility with IE6,7 we don't want apache to force-send a charset
	// HTTP header for AJAX query, otherwise, it's causing a JS error c00ce56e
	// So here, we enter the block only if we're NOT answering a AJAX call
	if (!(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'))
	{
		// We set utf8 as default charset to  be returned with the content
		// this can be overriden by header("ContentType...);
		ini_set("default_charset","utf8");
	}
}

$smarty->assign("utf8_charset_meta",
	'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
$smarty->assign("utf8_form_attribute",
	' accept-encoding="utf-8" ');
//============================= END i18n setup ===============================//

//========================== Session Handler config ==========================//

$session = new DRX_SessionHandler();
if (defined("SESSION_HANDLER_TYPE") && SESSION_HANDLER_TYPE === "DATABASE") {
	session_set_save_handler(array(&$session, "open"),
							 array(&$session, "close"),
							 array(&$session, "read"),
							 array(&$session, "write"),
							 array(&$session, "destroy"),
							 array(&$session, "gc"));
}
DRX::register("session", $session);
if(defined('APPLICATION_NAME'))
{
	//session_name(APPLICATION_NAME);
}
session_start();
//======================== End Session Handler config ========================//

//============================== Language config ==============================//
if (!defined('ACTIVATE_SMARTY_LANGUAGE_RESOURCE'))
{
	define ('ACTIVATE_SMARTY_LANGUAGE_RESOURCE', false);
}

if (!defined('DEFAULT_LANGUAGE'))
{
	define ('DEFAULT_LANGUAGE','en');
}

if (!defined('DEFAULT_LANGUAGE_PARAMETER_NAME'))
{
	define ('DEFAULT_LANGUAGE_PARAMETER_NAME','language');
}

if (!isset($authorized_languages) or !is_array($authorized_languages))
{
	$authorized_languages = array(DEFAULT_LANGUAGE);
}
DRX_MultiLanguage::initialize(DEFAULT_LANGUAGE,$authorized_languages);

// Should we change the current language?
$new_lang = DRX_RequestHandler::getString(DEFAULT_LANGUAGE_PARAMETER_NAME);
if($new_lang!='') {
	DRX_MultiLanguage::setLanguage($new_lang);
}

//============================== Language config ==============================//
require("DRX_Controller.php");

//Html Input - deprecated
$html_input = new HTMLInput( );
$smarty->assign("html_input", $html_input );

//Html Ouput - deprecated
$html_output = new HTMLOutput( );
$smarty->assign("output", $html_output );

?>